package com.coocaa.ops.plus.dashboard.v1.codegen.convert;


import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.coocaa.ops.plus.dashboard.v1.codegen.constant.TypeConstants;
import com.coocaa.ops.plus.dashboard.v1.codegen.model.ClassNameConfigModel;

import java.util.HashMap;
import java.util.Map;

/**
 * @author : bijiahao
 * @date : 2019/4/25.
 * @description: 类名转化工具
 * <p> </p>
 */
public class ClassNameConvert {

    private static final String UPDATE = "Update";
    private static final String QUERY = "Query";


    public static Map<String, String> convertName(String tableName2ClassName, ClassNameConfigModel classNameConfig) {
        Map<String, String> name = new HashMap<>(9);

        name.put(TypeConstants.ENTITY, convert2EntityName(tableName2ClassName, classNameConfig));
        name.put(TypeConstants.MODEL, convert2ModelName(tableName2ClassName, classNameConfig));
        name.put(TypeConstants.MAPPER, convert2MapperName(tableName2ClassName, classNameConfig));
        name.put(TypeConstants.XML, convert2XmlName(tableName2ClassName, classNameConfig));
        name.put(TypeConstants.BIZ, convert2BizName(tableName2ClassName, classNameConfig));
        name.put(TypeConstants.BIZ_IMPL, convert2BizImplName(tableName2ClassName, classNameConfig));
        name.put(TypeConstants.QUERY_PROVIDER, convert2QueryProviderName(tableName2ClassName, classNameConfig));
        name.put(TypeConstants.QUERY_PROVIDER_IMPL, convert2QueryProviderImplName(tableName2ClassName, classNameConfig));
        name.put(TypeConstants.UPDATE_PROVIDER, convert2UpdateProviderName(tableName2ClassName, classNameConfig));
        name.put(TypeConstants.UPDATE_PROVIDER_IMPL, convert2UpdateProviderImplName(tableName2ClassName, classNameConfig));
        name.put(TypeConstants.QUERY_SERVICE, convert2QueryServiceName(tableName2ClassName, classNameConfig));
        name.put(TypeConstants.QUERY_SERVICE_IMPL, convert2QueryServiceImplName(tableName2ClassName, classNameConfig));
        name.put(TypeConstants.UPDATE_SERVICE, convert2UpdateServiceName(tableName2ClassName, classNameConfig));
        name.put(TypeConstants.UPDATE_SERVICE_IMPL, convert2UpdateServiceImplName(tableName2ClassName, classNameConfig));
        name.put(TypeConstants.CONTROLLER, convert2ControllerName(tableName2ClassName, classNameConfig));
        return name;


    }

    /**
     * 表名称->类名
     *
     * @param tableName
     * @return
     */
    public static String convertTableName2ClassName(String tableName) {
        return StringUtils.capitalize(StringUtils.underlineToCamel(tableName));
    }

    /**
     * 表的类名->实体类名称
     *
     * @param tableName2ClassName
     * @return
     */
    public static String convert2EntityName(String tableName2ClassName, ClassNameConfigModel classNameConfig) {
        return tableName2ClassName + classNameConfig.getEntityName();
    }

    /**
     * 表的类名->Mapper接口名称
     *
     * @param tableName2ClassName
     * @return
     */
    public static String convert2MapperName(String tableName2ClassName, ClassNameConfigModel classNameConfig) {
        return "I" + tableName2ClassName + classNameConfig.getMapperName();
    }

    /**
     * 表的类名->xml文件名称
     *
     * @param tableName2ClassName
     * @return
     */
    public static String convert2XmlName(String tableName2ClassName, ClassNameConfigModel classNameConfig) {
        return "I" + tableName2ClassName + classNameConfig.getXmlName();
    }

    /**
     * 表的类名->查询Model类名称
     *
     * @param tableName2ClassName
     * @return
     */
    public static String convert2ModelName(String tableName2ClassName, ClassNameConfigModel classNameConfig) {
        return tableName2ClassName + classNameConfig.getModelName();
    }

    /**
     * 表的类名->Biz接口名称
     *
     * @param tableName2ClassName
     * @return
     */
    public static String convert2BizName(String tableName2ClassName, ClassNameConfigModel classNameConfig) {
        return "I" + tableName2ClassName + classNameConfig.getBizName();
    }

    /**
     * 表的类名->Biz实现名称
     *
     * @param tableName2ClassName
     * @return
     */
    public static String convert2BizImplName(String tableName2ClassName, ClassNameConfigModel classNameConfig) {
        return tableName2ClassName + classNameConfig.getBizImplName();
    }

    /**
     * 表的类名->查询Provider接口名称
     *
     * @param tableName2ClassName
     * @return
     */
    public static String convert2QueryProviderName(String tableName2ClassName, ClassNameConfigModel classNameConfig) {
        return "I" + tableName2ClassName + QUERY + classNameConfig.getProvider();
    }

    /**
     * 表的类名->查询Provider接口实现名称
     *
     * @param tableName2ClassName
     * @return
     */
    public static String convert2QueryProviderImplName(String tableName2ClassName, ClassNameConfigModel classNameConfig) {
        return tableName2ClassName + QUERY + classNameConfig.getProviderImpl();
    }

    /**
     * 表的类名->更新Provider接口名称
     *
     * @param tableName2ClassName
     * @return
     */
    public static String convert2UpdateProviderName(String tableName2ClassName, ClassNameConfigModel classNameConfig) {
        return "I" + tableName2ClassName + UPDATE + classNameConfig.getProvider();
    }

    /**
     * 表的类名->更新Provider接口实现名称
     *
     * @param tableName2ClassName
     * @return
     */
    public static String convert2UpdateProviderImplName(String tableName2ClassName, ClassNameConfigModel classNameConfig) {
        return tableName2ClassName + UPDATE + classNameConfig.getProviderImpl();
    }

    /**
     * 表的类名->查询Service接口名称
     *
     * @param tableName2ClassName
     * @return
     */
    public static String convert2QueryServiceName(String tableName2ClassName, ClassNameConfigModel classNameConfig) {
        return "I" + tableName2ClassName + QUERY + classNameConfig.getServiceName();
    }

    /**
     * 表的类名->查询Service实现名称
     *
     * @param tableName2ClassName
     * @return
     */
    public static String convert2QueryServiceImplName(String tableName2ClassName, ClassNameConfigModel classNameConfig) {
        return tableName2ClassName + QUERY + classNameConfig.getServiceImplName();
    }

    /**
     * 表的类名->更新Service接口名称
     *
     * @param tableName2ClassName
     * @return
     */
    public static String convert2UpdateServiceName(String tableName2ClassName, ClassNameConfigModel classNameConfig) {
        return "I" + tableName2ClassName + UPDATE + classNameConfig.getServiceName();
    }

    /**
     * 表的类名->更新Service实现名称
     *
     * @param tableName2ClassName
     * @return
     */
    public static String convert2UpdateServiceImplName(String tableName2ClassName, ClassNameConfigModel classNameConfig) {
        return tableName2ClassName + UPDATE + classNameConfig.getServiceImplName();
    }

    /**
     * 表的类名->Service接口名称
     *
     * @param tableName2ClassName
     * @return
     */
    public static String convert2ServiceName(String tableName2ClassName, ClassNameConfigModel classNameConfig) {
        return "I" + tableName2ClassName + classNameConfig.getServiceName();
    }

    /**
     * 表的类名->Service实现名称
     *
     * @param tableName2ClassName
     * @return
     */
    public static String convert2ServiceImplName(String tableName2ClassName, ClassNameConfigModel classNameConfig) {
        return tableName2ClassName + classNameConfig.getServiceImplName();
    }

    /**
     * 表的类名->控制器名称
     *
     * @param tableName2ClassName
     * @return
     */
    public static String convert2ControllerName(String tableName2ClassName, ClassNameConfigModel classNameConfig) {
        return tableName2ClassName + classNameConfig.getControllerName();
    }

    public static String convert2AuditTaskProviderImplName(String tableName2ClassName, ClassNameConfigModel classNameConfig) {
        return tableName2ClassName + "AuditTaskProviderImpl";
    }

    public static String convert2HistoryProviderImplName(String tableName2ClassName, ClassNameConfigModel classNameConfig) {
        return tableName2ClassName + "HistoryProviderImpl";
    }

    public static String convert2RlsUpdateProviderImplName(String tableName2ClassName, ClassNameConfigModel classNameConfig) {
        return tableName2ClassName + "RlsUpdateProviderImpl";
    }

    public static String convert2RlsUpdateProviderName(String tableName2ClassName, ClassNameConfigModel classNameConfig) {
        return "I" + tableName2ClassName + "RlsUpdateProvider";
    }

    public static String convert2HistoryMapperName(String tableName2ClassName, ClassNameConfigModel classNameConfig) {
        return "I" + tableName2ClassName + "HistoryMapper";
    }

    public static String convert2HistoryXmlName(String tableName2ClassName, ClassNameConfigModel classNameConfig) {
        return "I" + tableName2ClassName + "HistoryMapper";
    }

    public static String convert2HistoryTableEntityName(String tableName2ClassName, ClassNameConfigModel classNameConfig) {
        return tableName2ClassName + "HistoryEntity";
    }
}
